package com.webframe.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.webframe.constant.WFConstant;
import com.webframe.service.def.ITableOperationService;

/**
 * 类功能描述：
 *
 * Description: 
 */
@Controller
@RequestMapping("/tableRowDelete")
public class TableRowDeleteController extends BaseController
{
	@Autowired
	private ITableOperationService tableOperationService;
	/* (non-Javadoc)
	 * @see com.berheley.bi.web.controller.BaseController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@RequestMapping(method = RequestMethod.POST)
	protected ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		String tableName = request.getParameter(WFConstant.Constant_TableName_);
		String id= request.getParameter(WFConstant.Constant_PK_);
		String succesePage =request.getParameter(WFConstant.Constant_Success_PAGE_);
		String errorPage = request.getParameter(WFConstant.Constant_Error_PAGE_);
		String isAjax = request.getParameter(WFConstant.IS_AJAX_);
		String isRedirct = request.getParameter(WFConstant.Is_Redirect_);
		String targetPage= succesePage;
		tableOperationService.doDeleteExecuteByID(tableName, id);
		if("true".equalsIgnoreCase(isAjax))
		{
			return null;
		}
		if("true".equalsIgnoreCase(isRedirct))
		{
			return new ModelAndView("redirect:"+targetPage);
		}
		else
		{
			return new ModelAndView(targetPage);
		}
	}
}
